Skip to content

Editorial review: Update docs for Chrome 137 WebGPU additions #39732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ The **`copyBufferToBuffer()`** method of the
## Syntax

```js-nolint
copyBufferToBuffer(source, destination)
Copy link
Collaborator

@hamishwillee hamishwillee Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec says description does not indicate that size is optional in https://gpuweb.github.io/gpuweb/#commands-buffer-copies , but does indicate it in the IDL https://gpuweb.github.io/gpuweb/#gpucommandencoder

So, I think that there are two options, one for copying the whole buffer from 0, and one for copying part of the buffer from 0. I think the note below is still fine though, because it refers to copying the whole buffer.
Might be worth some comment on this case with size though.

Suggested change
copyBufferToBuffer(source, destination)
copyBufferToBuffer(source, destination)
copyBufferToBuffer(source, destination, size)

copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size)
```

### Parameters

- `source`
- : The {{domxref("GPUBuffer")}} to copy from.
- `sourceOffset`
- `sourceOffset` {{optional_inline}}
- : The offset, in bytes, into the `source` to begin copying from.
- `destination`
- : The {{domxref("GPUBuffer")}} to copy to.
- `destinationOffset`
- `destinationOffset` {{optional_inline}}
- : The offset, in bytes, into the `destination` to begin copying to.
- `size`
- `size` {{optional_inline}}
- : The number of bytes to copy.

> [!NOTE]
> The `sourceOffset`, `destinationOffset`, and `size` can be omitted if you are copying the entire source buffer to the destination buffer.
### Return value

None ({{jsxref("Undefined")}}).
Expand All @@ -49,14 +53,14 @@ The following criteria must be met when calling **`copyBufferToBuffer()`**, othe

## Examples

In our [basic compute demo](https://mdn.github.io/dom-examples/webgpu-compute-demo/), we use `copyBufferToBuffer()` to copy the contents of our `output` buffer to the `stagingBuffer`.
In our [basic compute demo](https://mdn.github.io/dom-examples/webgpu-compute-demo/), we use `copyBufferToBuffer()` to copy the contents of our `outputBuffer` to the `stagingBuffer`.

```js
//

// Create an output buffer to read GPU calculations to, and a staging buffer to be mapped for JavaScript access

const output = device.createBuffer({
const outputBuffer = device.createBuffer({
size: BUFFER_SIZE,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC,
});
Expand All @@ -75,13 +79,16 @@ const commandEncoder = device.createCommandEncoder();

// Copy output buffer to staging buffer
commandEncoder.copyBufferToBuffer(
output,
outputBuffer,
0, // Source offset
stagingBuffer,
0, // Destination offset
BUFFER_SIZE,
);

// Since we are copying the entire buffer, this can be shortened to
// commandEncoder.copyBufferToBuffer(outputBuffer, stagingBuffer);

//
```

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/gpudevice/createbindgroup/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ createBindGroup(descriptor)
- `GPUBufferBinding` (which wraps a {{domxref("GPUBuffer")}}; see [GPUBufferBinding objects](#gpubufferbinding_objects) for a definition)
- {{domxref("GPUExternalTexture")}}
- {{domxref("GPUSampler")}}
- {{domxref("GPUTextureView")}}
- {{domxref("GPUTextureView")}}; can be used in place of a `GPUExternalTexture` provided it is compatible (a 2D format with a single subresource, that is, [`dimension: "2d"`](/en-US/docs/Web/API/GPUTexture/createView#dimension)).
- `label` {{optional_inline}}
- : A string providing a label that can be used to identify the object, for example in {{domxref("GPUError")}} messages or console warnings.
- `layout`
Expand Down